<template>
    <div>
        <table>
            <tr>
                <td>姓名</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>数量</td>
                <td><input type="text" v-model="data.num"></td>
            </tr>
            <tr>
                <td>价钱</td>
                <td><input type="text" v-model="data.price"></td>
            </tr>
            <tr>
                <td>图片</td>
                <td>
                <input type="file" @change="upload" >
                <img :src="'https://localhost:7087'+data.img" style="height: 100px;width: 100px;" alt="">
            </td>
            </tr>
            <tr>
                <td>上下架</td>
                <td>
                    <input type="radio" v-model="data.shen" :value="true">上架
                    <input type="radio" v-model="data.shen" :value="false">下架
                </td>
            </tr>
            <tr>
                <td><input type="button" value="添加" @click="Add"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue';
import axios  from 'axios';
import { useRouter } from 'vue-router';

const rount=useRouter()

const upload=(e:any)=>{
    var f=e.target.files[0];
    var fd=new FormData();
    fd.append("file",f);
    axios.post("https://localhost:7087/api/UpLog",fd).then(res=>{
        data.value.img=res.data;
    })
}


const data=ref({
  "id": 0,
  "name": "",
  "num": "",
  "price": 0,
  "img": "",
  "shen": true
})


const Add=()=>{
    axios.post("https://localhost:7087/api/User/Add",data.value).then(res=>{
        if(res.data>0){
            alert('成功')
            rount.push({path:'/Showview'});
        }
        else{
            alert('失败')
        }
    })
}



</script>

<style scoped>

</style>


